﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Visa.DB;
using System.Data;

namespace Visa.Service
{
   public class EmailSensSev
    {
        private VisaEntities db = new VisaEntities();

        public int addOrUpdateNews(EmailSend entity)
        {
            db.Entry(entity).State = entity.Id == -1 ? EntityState.Added : EntityState.Modified;
            db.SaveChanges();
            return entity.Id;
        }

        public void DeleteEmailSend(int id)
        {
            var c = db.EmailSends.SingleOrDefault(l => l.Id == id);
            db.EmailSends.Remove(c);
            db.SaveChanges();
        }

        public EmailSend GetById(int id)
        {
            try
            {
                return db.EmailSends.SingleOrDefault(l => l.Id == id);
            }
            catch { return null; }
        }

        public List<EmailSend> GetAllNews()
        {
            try
            {
                return db.EmailSends.OrderByDescending( m => m.DateCreate).ToList() ;
            }
            catch { return null; }
        }
    }
}
